package Dao;

import entity.Goods;
import entity.Type;
import util.DatabaseUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TypeDaoImpl extends BasDao implements TypeDao {
    Connection conn;
    public TypeDaoImpl(Connection conn) {
        super(conn);
    }
    @Override
    public List<Type> getSeries(String name) {
        ResultSet rs = null;
        Type type=null;
        List<Type> list = new ArrayList<>();
        PreparedStatement pstmt = null;
        String sql = "select * from Type where 1=1 and name like ?";
        try {
            rs =  super.executeQuery(sql,"%"+name+"%");
            while (rs.next()){
                type = new Type();
                type.setId(rs.getInt("id"));
                type.setName(rs.getString("name"));
                list.add(type);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            DatabaseUtil.closeAll(null, pstmt, rs);
        }
        return list;
    }

    public static void main(String[] args) {
        DatabaseUtil baseDao=new DatabaseUtil();
        Connection conn = baseDao.getConnection();
        TypeDao typeDao = new TypeDaoImpl(conn);
        List<Type> list = typeDao.getSeries("");
        System.out.println(list);
    }
}
